package model

import "github.com/jmoiron/sqlx"

// User _
type User struct {
	ID   int64  `db:"id" form:"id"`
	Name string `db:"name" form:"name"`
}

// GetUser _
func GetUser(db *sqlx.DB, id int64) (user User, err error) {
	err = db.Get(&user, "select id,name from user where id = ?", id)
	return
}

func AddUser(db *sqlx.DB, user *User) (err error) {
	_, err = db.NamedExec("insert into user(name) values(:name)", user)
	return
}

func UpdateUser(db *sqlx.DB, user *User) (err error) {
	_, err = db.NamedExec("update user set name = :name where id = :id", user)
	return
}
